package com.wlhse.controller;

import com.wlhse.entity.CheckItemPojo;
import com.wlhse.entity.CheckItemStardardPojo;
import com.wlhse.service.CheckItemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("CheckItemController")
@RequestMapping("/api/v3")
//检查项配置
public class CheckItemController {

    @Resource
    private CheckItemService checkItemService;


    @RequestMapping(value = "/check_item/tree", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String get1() {
        return checkItemService.getTreeDto();
    }

//    @RequestMapping(value = "/check_item/tree/all", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
//    public String get2() {
//        return checkItemService.getTreeDtoV2();
//    }

    @RequestMapping(value = "/check_item", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.addCheckItem(checkItemPojo.getCheckItemCode(), checkItemPojo.getCheckItemName());
    }

    @RequestMapping(value = "/check_item", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.updateCheckItem(checkItemPojo);
    }

    @RequestMapping(value = "/check_item", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteCheckItem(@RequestBody CheckItemPojo checkItemPojo) {
        return checkItemService.deleteCheckItem(checkItemPojo);
    }

    //查询content
    @RequestMapping(value = "/check_item", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getCheckItemContent(@RequestParam(value = "checkItemCode", required = false, defaultValue = "") String checkItemCode) {
        return checkItemService.getCheckItemContent(checkItemCode);
    }

    //新增
    @RequestMapping(value = "/check_item_standard", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addCheckItemStandard(@RequestBody CheckItemStardardPojo checkItemStardardPojo) {
        return checkItemService.addCheckItemStandard(checkItemStardardPojo);
    }

    //删除
    @RequestMapping(value = "/check_item_standard/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteCheckItemStandard(@PathVariable("id") String id) {
        return checkItemService.deleteCheckItemStandard(id);
    }
}
